package model;

import java.util.LinkedList;

public class Arena {

	private static Arena instance = null;
	private LinkedList<Player> bobs;
	private Player selected;
	private boolean cliked;
	private double xClick = 0, yClick = 0;
	private LinkedList<Macaco> macacos;

	public Player getSelected() {
		return this.selected;
	}

	/* Getters */

	public boolean isCliked() {
		return cliked;
	}

	public double getXClick() {
		return xClick;
	}
	
	public double getYClick() {
		return yClick;
	}

	public LinkedList<Player> getBobs() {
		return bobs;
	}

	/* Setters */

	public void setSelected(Player selected) {
		this.selected = selected;
	}

	/**
	 * M�todo de acesso � instancia da classe Arena. Se a inst�ncia for
	 * nula, ela � inicializada.
	 * 
	 * @return Uma inst�ncia da classe Arena.
	 */
	public static Arena instanceOf() {
		if (instance == null) {
			new Arena();
		}
		return instance;
	}

	public void setCliked(boolean cliked) {
		this.cliked = cliked;
	}

	public void setAuraPoint(double x, double y) {
		this.xClick = x;
		this.yClick = y;
	}

	/**
	 * Adiciona um novo para a lista de personagens na Arena.
	 * 
	 * @param player
	 *            O novo a ser adicionado.
	 */
	public void addPlayer(Player player) {
		this.bobs.addLast(player);
	}

	/**
	 * Construtor da classe Arena. Inicializa a lista de personagens, adiciona
	 * um primeiro personagem e seleciona ele.
	 */
	public Arena() {
		Arena.instance = this;
		this.bobs = new LinkedList<Player>();
		this.bobs.add(new Player());
		this.selected = this.bobs.getFirst();
		this.macacos = new LinkedList<Macaco>();
		this.cliked = false;
	}

	public LinkedList<Macaco> getMacacos() {
		return macacos;
	}

	public void addMacaco(Macaco macaco) {
		this.macacos.addLast(macaco);
	}

	public boolean isProximate(Player player, Player target) {
		int distX = 0;
		int distY = 0;
		if (player.equals(target)) {
			return false;
		}
		distX = (int) (player.getDirX() - target.getDirX());
		distY = (int) (player.getDirY() - target.getDirY());
		System.out.println("dif " + distX + " " + distY);
		if (distX < 0) {
			distX = distX * -1;
		}
		if (distY < 0) {
			distY = distY * -1;
		}
		if (distX < 1 && distY < 1) {
			return true;
		}

		return false;
	}
}
